package com.shop.base;

import com.shop.result.ResultVO;
import org.springframework.http.HttpStatus;

/**
 * @author XCH
 * @date 2025/5/13
 */
public class BaseController {

    /**
     * 响应成功（带数据）
     * @param data
     * @return
     * @param <T>
     */
    protected  <T> ResultVO<T> success(T data) {
        ResultVO<T> vo = new ResultVO<>();
        vo.setCode(HttpStatus.OK.value());
        vo.setData(data);
        return vo;
    }

    /**
     * 仅响应成功
     * @return
     * @param <T>
     */
    protected <T> ResultVO<T> success() {
        ResultVO<T> vo = new ResultVO<>();
        vo.setCode(HttpStatus.OK.value());
        return vo;
    }
    protected <T> ResultVO<T> success(Integer code, String message, T data) {
        ResultVO<T> vo = new ResultVO<>();
        vo.setCode(code);
        vo.setMessage(message);
        vo.setData(data);
        return vo;
    }
    protected <T> ResultVO<T> success(Integer code, String message) {
        ResultVO<T> vo = new ResultVO<>();
        vo.setCode(code);
        vo.setMessage(message);
        return vo;
    }
    protected <T> ResultVO<T> success(String message, T data) {
        ResultVO<T> vo = new ResultVO<>();
        vo.setCode(HttpStatus.OK.value());
        vo.setData(data);
        return vo;
    }
    /**
     * 响应失败
     * @param message
     * @return
     * @param <T>
     */
    protected <T> ResultVO<T> error(String message) {
        ResultVO<T> vo = new ResultVO<>();
        vo.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
        vo.setMessage(message);
        return vo;
    }

    /**
     * 响应失败
     * @param code
     * @param message
     * @return
     * @param <T>
     */
    protected <T> ResultVO<T> error(Integer code, String message) {
        ResultVO<T> vo = new ResultVO<>();
        vo.setCode(code);
        vo.setMessage(message);
        return vo;
    }
    /**
     * 响应失败
     * @param status
     * @param message
     * @return
     * @param <T>
     */
    protected <T> ResultVO<T> error(HttpStatus status, String message) {
        ResultVO<T> vo = new ResultVO<>();
        vo.setCode(status.value());
        vo.setMessage(message);
        return vo;
    }
    /**
     * 响应失败
     * @param status
     * @return
     * @param <T>
     */
    protected <T> ResultVO<T> error(HttpStatus status) {
        ResultVO<T> vo = new ResultVO<>();
        vo.setCode(status.value());
        vo.setMessage(status.getReasonPhrase());
        return vo;
    }
    /**
     * 响应失败
     * @param code
     * @return
     * @param <T>
     */
    protected <T> ResultVO<T> error(Integer code) {
        ResultVO<T> vo = new ResultVO<>();
        vo.setCode(code);
        return vo;
    }

    /**
     * 响应失败
     * @return
     * @param <T>
     */
    protected <T> ResultVO<T> error() {
        ResultVO<T> vo = new ResultVO<>();
        vo.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
        return vo;
    }
}